
// stdafx.cpp : source file that includes just the standard includes
// inf2csv.pch will be the pre-compiled header
// stdafx.obj will contain the pre-compiled type information

#include "stdafx.h"
#include "csvline.h"
/*
#if defined _M_IX86
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='x86' publicKeyToken='6595b64144ccf1df' language='*'\"")
#elif defined _M_X64
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='amd64' publicKeyToken='6595b64144ccf1df' language='*'\"")
#else
#pragma comment(linker,"/manifestdependency:\"type='win32' name='Microsoft.Windows.Common-Controls' version='6.0.0.0' processorArchitecture='*' publicKeyToken='6595b64144ccf1df' language='*'\"")
#endif	*/

bool cmn::CommonTrackMenu(CWnd* pWnd, const POINT & apoint, int subindex)
{
	CMenu	themenu;
	CWnd * pMainWnd = pWnd;
	CMenu* pmenuSub = NULL;

	pMainWnd = AfxGetMainWnd();
	//	TODO: special menu resource
	if (subindex > 66) 
	{
		themenu.LoadMenu(subindex);
		pmenuSub = themenu.GetSubMenu(1);
		pmenuSub->DeleteMenu(0, MF_BYPOSITION);
		pmenuSub->DeleteMenu(0, MF_BYPOSITION);
		pmenuSub->DeleteMenu(ID_VIEW_LIST, MF_BYCOMMAND);
	}
	else
		pmenuSub = pMainWnd->GetMenu()->GetSubMenu(subindex);

	POINT thepoint = apoint;
	if (pmenuSub) 
	if (!(apoint.x + 1) || !(apoint.y + 1))
	{
		RECT therect;
		::GetCursorPos(&thepoint);
		pWnd->GetWindowRect(& therect);
		therect.right  -= ::GetSystemMetrics(SM_CXICON);
		therect.bottom -= ::GetSystemMetrics(SM_CYICON);
		if (::IsRectEmpty(& therect)) pmenuSub = NULL;
		if (!(::PtInRect(& therect, thepoint))) 
				pmenuSub = NULL;
	}

	if (!pmenuSub) return false;

	pmenuSub->TrackPopupMenu(TPM_LEFTALIGN | TPM_RIGHTBUTTON, 
					thepoint.x, thepoint.y, pMainWnd);
	pmenuSub = NULL;

	return true;
}

void cmn::ClipboardCopyText(const CString& text)
{
	if (::OpenClipboard(NULL))
	{
		::EmptyClipboard();
		unsigned thelen = text.GetLength() + 1;
		HGLOBAL hGlob = ::GlobalAlloc(GMEM_FIXED, 2 * thelen);
			::wcsncpy((WCHAR *) hGlob, text, thelen);
		if(!::SetClipboardData(CF_UNICODETEXT, hGlob)) ::GlobalFree(hGlob);
		::CloseClipboard();
	}
}

bool restorePos(CWinApp * pApp, const POINT & aminiPoint, CREATESTRUCT& cs)
{
	LPBYTE	pByte = NULL;
	//	BOOL retval = ::GetWindowPlacement(m_hWnd, & wp);
	UINT thelen(0) ;	//	= sizeof(RECT);
	BOOL retval = pApp->GetProfileBinary(L"window", L"pos",  & pByte, & thelen);
	if(!retval || (thelen != sizeof(RECT))) 
	{
		if (pByte) delete [] pByte;
		return false;
	}

	bool result(false);	//	if(!(::IsRectEmpty(pRect)))
	LPRECT	pRect = (LPRECT) pByte;
	RECT	thesize = { 0, 0, pRect->right - pRect->left, pRect->bottom - pRect->top };
	CRect	screen(0, 0, ::GetSystemMetrics(SM_CXSCREEN), ::GetSystemMetrics(SM_CYSCREEN));
	if (!(::PtInRect(& thesize, screen.BottomRight())) && ::PtInRect(& thesize, aminiPoint))
	if (::PtInRect(& screen, CPoint(pRect->left, pRect->top)))
	if (::PtInRect(& screen, CPoint(pRect->right, pRect->bottom)))
	{	
		cs.cx = thesize.right;	cs.cy = thesize.bottom;
		cs.x = pRect->left; cs.y = pRect->top;
/*
	// the following correction is needed when the taskbar is at the left or top and it is not "auto-hidden"
		RECT workArea;	
		::GetSystemMetrics(SM_CXICON); ::GetSystemMetrics(SM_CYICON);
		SystemParametersInfo(SPI_GETWORKAREA, 0, &workArea, 0);
		.m_iMainLeft += workArea.left;
		.m_iMainTop += workArea.top;
		*/

		AfxGetApp()->m_nCmdShow = SW_SHOWNORMAL;	//	SW_SHOWDEFAULT
		result = true;
	}

	delete [] pByte;

	return result;
}
